// pages/opt_user_admin/opt_page/one_minute_piple/one_minute_piple.js
var app = getApp()
//常量数据配置
var ConstantData = require('../../../../../common/constant_data.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputHospital: '',
    noneDataStat: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.showLoading({
      title: '加载中...',
      mask: true
    }); 
    app.executeRequest(function (header) {
      wx.request({
        url: ConstantData.CONSTATNT_DATA.BASE_URL + '/lease_admin/low_electricity/oneminute_types',
        header: header,
        success: function (res) {
          getApp().hideLoading();
          console.log("hostipal---->", res);
          if (res.data.result === 0) {
            that.setData({
              hospitalList: res.data.data,
              originHospitalList:res.data.data
            })
          }
        }
      })
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  inputHospital:function(e) {

    this.setData({
      inputHospital: e.detail.value
    });

    var hospitals = new Array();
    var originHospitalList = this.data.originHospitalList;
    for (var i = 0; i < originHospitalList.length; i++) {
      if (originHospitalList[i].ti_name.indexOf(this.data.inputHospital) != -1) {
        hospitals.push(originHospitalList[i]);
      }
    }
    if (this.data.inputHospital == '') {
      hospitals = this.data.originHospitalList;
    } else if (hospitals.length == 0) {
      this.setData({
        noneDataStat: true
      });
    } else {
      this.setData({
        noneDataStat: false
      });
    }
    this.setData({
      hospitalList: hospitals
    })

  },

  /** 
* 点击 ,进入低电量归位桩列表
*/
  toOneMinutePipleList: function (e) {
    var typeId = e.currentTarget.dataset.hospitalid;
    var hospitalName = e.currentTarget.dataset.hospitalname;
    wx.navigateTo({
      url: 'piple_list/piple_list?typeId=' + typeId + "&hospitalName=" + hospitalName,
    });
  }

})